// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

// 防止头文件重复包含

#include "GameFramework/CharacterMovementComponent.h"
#include "NativeGameplayTags.h"

// 包含UE4/UE5的角色移动组件基类和游戏标签功能

#include "LyraCharacterMovementComponent.generated.h"

// 包含UE生成的反射代码

class UObject;
struct FFrame;

// 前向声明UObject类和FFrame结构体

LYRAGAME_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_Gameplay_MovementStopped);
// 声明外部游戏标签 TAG_Gameplay_MovementStopped

/**
 * FLyraCharacterGroundInfo
 *
 *	Information about the ground under the character.  It only gets updated as needed.
 */
// 定义角色地面信息结构体，仅在需要时更新
USTRUCT(BlueprintType)
struct FLyraCharacterGroundInfo
{
	GENERATED_BODY()
	// UE反射宏

	FLyraCharacterGroundInfo()
		: LastUpdateFrame(0)
		, GroundDistance(0.0f)
	{}
	// 构造函数，初始化成员变量

	uint64 LastUpdateFrame;
	// 记录最后更新帧数，用于缓存验证

	UPROPERTY(BlueprintReadOnly)
	FHitResult GroundHitResult;
	// 地面检测结果，蓝图只读

	UPROPERTY(BlueprintReadOnly)
	float GroundDistance;
	// 地面距离，蓝图只读
};

/**
 * ULyraCharacterMovementComponent
 *
 *	The base character movement component class used by this project.
 */
// 项目使用的基类角色移动组件
UCLASS(Config = Game)
class LYRAGAME_API ULyraCharacterMovementComponent : public UCharacterMovementComponent
{
	GENERATED_BODY()
	// UE反射宏

public:
	ULyraCharacterMovementComponent(const FObjectInitializer& ObjectInitializer);
	// 构造函数

	virtual void SimulateMovement(float DeltaTime) override;
	// 重写模拟移动函数

	virtual bool CanAttemptJump() const override;
	// 重写跳跃尝试检查函数

	// Returns the current ground info.  Calling this will update the ground info if it's out of date.
	UFUNCTION(BlueprintCallable, Category = "Lyra|CharacterMovement")
	const FLyraCharacterGroundInfo& GetGroundInfo();
	// 获取地面信息，如果过期会更新，蓝图可调用

	void SetReplicatedAcceleration(const FVector& InAcceleration);
	// 设置复制的加速度

	//~UMovementComponent interface
	virtual FRotator GetDeltaRotation(float DeltaTime) const override;
	// 重写获取旋转变化量函数
	virtual float GetMaxSpeed() const override;
	// 重写获取最大速度函数
	//~End of UMovementComponent interface

protected:
	virtual void InitializeComponent() override;
	// 重写组件初始化函数

protected:
	// Cached ground info for the character.  Do not access this directly!  It's only updated when accessed via GetGroundInfo().
	FLyraCharacterGroundInfo CachedGroundInfo;
	// 缓存的地面信息，警告不要直接访问

	UPROPERTY(Transient)
	bool bHasReplicatedAcceleration = false;
	// 标记是否有复制的加速度，临时属性不保存
};